#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <unistd.h>


void shoupiao(int sig) 
{
    //SIGINT 开车
    if(sig == SIGINT) {
        kill(getppid(), SIGUSR1);
    }
    if(sig == SIGUSR1) {
        printf("please get off the bus!\n");
    }
    if(sig == SIGUSR1) {
        printf("please get off the bus!\n");
    }
}

void siji(int sig)
{
    //SIGSTP 车到总站
    if(sig == SIGTSTP) {
        kill(0, SIGUSR1);
    }
    if(sig == SIGUSR1) {
        printf("let's gogogo!\n");
    }
    if(sig == SIGUSR2) {
        printf("stop the bus!\n");
    }
}

int main(int argc, const char *argv[]) 
{
    pid_t pid, ppid;
    int num = 10;

    pid = fork();
    if(pid == -1) {
        perror("创建子进程失败！\n");
        return -1;
    } else if(pid == 0) {
        //售票员
        signal(SIGTSTP, SIG_IGN);
        signal(SIGINT, shoupiao);
        signal(SIGQUIT, shoupiao);
        signal(SIGUSR1, shoupiao);
    } else {
        //司机
        signal(SIGINT, SIG_IGN);
        signal(SIGTSTP, siji);
        signal(SIGUSR1, siji);
        signal(SIGUSR2, siji);
    }
    while(1);
    return 0;
}

